DecLoop
Do .. DecLoop
 
Parameters: NONE
Returns: NONE
 

     Do / DecLoop pairs are a conditional variation of the Do-Loop structure. DecLoop will decrease an integer or float variable until it's less than 0. So each loop the counter variable is decreased by one, until it reaches zero where execution falls through out of the loop.




FACTS:


     * Do - DecLoop must be paired.

     * The Do must preceed the DecLoop statement. You'll get an error otherwise.

     * Do - DecLoop is a faster alternative to other conditional loop structures. But limited since it can only count down.

     * See Loops Tutorial.




Mini Tutorial #1:


     Showing the use of a Do-DecLoop structure

  
  Counter=5
  Do
     Print Counter
     Sync
  DecLoop Counter
  
  WaitKey
  



This code will output:
  
  5
  4
  3
  2
  1
  0
  





Mini Tutorial #2: Emulating DecLoop


     This example show how you can emulate the Do-DecLoop structure.


  
  // Count down loop using Decloop
  Counter =10
  Do
     Print Counter
  DecLoop counter
  
  
  
  // Emulated version of DecLoop
  Counter =10
  Do
     Print Counter
     Counter--
  Loop counter<0
  
  
  Sync
  WaitKey
  






 
Related Info: Continue | Do | Exit | ExitDo | For | Loop | Loops | Repeat | While :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com